home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 2002 Tom Parker (tom@carrott.org),
- Matthias Münch (matthias@amigaworld.de)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- In addition, as a special exception, Tom Parker and Matthias Münch give
- permission to link the code of this program with a TCP stack of your
- choice, any official MUI libraries or classes and any custom MUI classes
- that should be necessary for the operation of this program. This
- exception also gives you permission to distribute linked combinations
- including this software with any of the before-mentioned libraries and
- classes. You must obey the GNU General Public License in all respects for
- all of the code used other than that provided by the before-mentioned
- libraries and classes. As part of this exception you are obliged to
- follow the license terms of the before-mentioned libraries, this license
- does not compel you to follow those terms, but if you do not then you may
- not link with those libraries. If you modify this file, you may extend
- this exception to your version of the file, but you are not obligated to
- do so. If you do not wish to do so, delete this exception statement from
- your version.
- */
- /*
- ** chat area
- */
-
- #include "common.h"
-
- #include <stdlib.h>
- #include <string.h>
-
- #include <proto/exec.h>
- #include <exec/memory.h>
-
- #include <MUI/NListview_mcc.h>
-
- typedef struct
- {
- int fmt;
- char *nick;
- char *text;
- } cmsg;
-
- static ULONG chatarea_new(struct IClass *cl, Object *obj, struct opSet *msg);
- static ULONG chatarea_dispose(struct IClass *cl, Object *obj, Msg msg);
- static MUI_LIST_DISP_DECL(chatarea_disp, cmsg *m);
-
-
- static char *pstrdup(void *pool, char *src, int len)
- {
- char *t;
-
- if(len == -1) len = strlen(src);
- if(len == 0) return(NULL);
- t = AllocPooled(pool, len + 1);
- if(!t) return(NULL);
- memcpy(t, src, len);
- t[len] = '\0';
- return t;
- }
-
-
- MUI_DISPATCH(chatarea_dispatch)
- {
- switch(msg->MethodID)
- {
- case OM_NEW:
- return chatarea_new(cl, obj, (APTR)msg);
-
- case OM_DISPOSE:
- return chatarea_dispose(cl, obj, (APTR)msg);
-
- case CHATAREA_ADD:
- {
- struct chatareadata *data = INST_DATA(cl,obj);
- cmsg *m;
- char *t, *t2, *nick;
-
- nick = (char *)MARG2;
- t2 = convert_locale((char *)MARG3);
- while(1)
- {
- if(!t2 || t2[0] == '\0') break;
- m = AllocPooled(data->pool, sizeof(cmsg));
- if(!m) return(0);
- m->fmt = (int)MARG1;
- if(nick)
- {
- m->nick = pstrdup(data->pool, nick, -1);
- nick = NULL;
- }
- else
- {
- m->nick = NULL;
- }
- t = strchr(t2, '\n');
- if(t)
- {
- m->text = pstrdup(data->pool, t2, t-t2);
- t2 = t + 1;
- }
- else
- {
- m->text = pstrdup(data->pool, t2, -1);
- t2 = NULL;
- }
- DoMethod(data->list, MUIM_NList_InsertSingleWrap, m, MUIV_NList_Insert_Bottom, 2, 0);
- }
- set(data->list, MUIA_NList_First, MUIV_NList_Active_Bottom);
- return 0;
- }
-
- case CHATAREA_FLUSH:
- {
- struct chatareadata *data = INST_DATA(cl,obj);
-
- DoMethod(data->list, MUIM_NList_Clear);
-
- DeletePool(data->pool);
- data->pool = CreatePool(MEMF_PUBLIC, 1024, 1000);
- return 0;
- }
-
- }
- return DoSuperMethodA(cl,obj,msg);
- }
-
-
- static ULONG chatarea_new(struct IClass *cl, Object *obj, struct opSet *msg)
- {
- static struct Hook dispHook = { {0,0}, &chatarea_disp, NULL, NULL };
- struct chatareadata *data;
- Object *list;
- void *pool;
-
- pool = CreatePool(MEMF_PUBLIC, 1024, 1000);
- if(!pool) return(0);
-
- obj = (Object *)DoSuperNew(cl,obj,
- MUIA_NListview_NList, (ULONG) list = NListObject,
- ReadListFrame,
- MUIA_NList_Input, FALSE,
- MUIA_ContextMenu, NULL,
- MUIA_NList_DefaultObjectOnClick, FALSE,
- MUIA_NList_AutoCopyToClip, TRUE,
- MUIA_NList_TypeSelect, MUIV_NList_TypeSelect_Char,
- MUIA_NList_AutoVisible, TRUE,
- MUIA_NList_Format, "BAR,",
- MUIA_NList_DisplayHook, &dispHook,
- End,
- TAG_MORE, msg->ops_AttrList);
-
- if(!obj)
- {
- DeletePool(pool);
- return 0;
- }
-
- data = INST_DATA(cl,obj);
- data->list = list;
- data->pool = pool;
-
- return (ULONG)obj;
- }
-
-
- static ULONG chatarea_dispose(struct IClass *cl, Object *obj, Msg msg)
- {
- struct chatareadata *data = INST_DATA(cl,obj);
-
- if(data->pool) DeletePool(data->pool);
- return DoSuperMethodA(cl, obj, msg);
- }
-
-
- MUI_LIST_DISP_STATIC(chatarea_disp, cmsg *m)
- {
- switch(m->fmt)
- {
- case 1:
- array[DISPLAY_ARRAY_MAX + 1] = "\33i";
- break;
- case 2:
- array[DISPLAY_ARRAY_MAX] = "\33b";
- array[DISPLAY_ARRAY_MAX + 1] = "\33b";
- break;
- }
-
- *array++ = m->nick;
- *array = m->text;
-
- return 0;
- }
-